var mongoose = require('mongoose');

mongoose.connect('mongodb://localhost/wechat');

var Schema = mongoose.Schema;

var ObjectId = mongoose.Schema.Types.ObjectId;

var fansSchema = new Schema({
	unique_id : Number,
	openid: String,
	subscribe: Number,
	nickname: String,
	sex: Number,
	city: String,
	province: String,
	country: String,
	headimgurl: String,
	subscribe_time: Number,
	unionid: String,
	remark: String,
	groupid: Number,
	created_at: Number
});

var messageSchema = new Schema({
	unique_id : Number,
	fans: { type: Schema.Types.ObjectId, ref: 'we_fans' },
	message: String,
	created_at: Number
});

module.exports = Model;

function Model (app) {
	
	this.Message = mongoose.model('we_messages', messageSchema); 
	
	this.Fans = mongoose.model('we_fans', fansSchema); 
	
}

